// =============================================================================
// Stata Do-file for "Gender, Digital Media, and Parenthood Attitudes" Analysis
//
// Last updated: 2025-11-13
// Purpose: This file uses MTF data to analyze the 'baseline' gender differences
//          in how media use affects parenthood attitudes among adolescents 
//          during the pre-pandemic period (2018-2020).
//          (Hypothesis 1: Schema-filling for male students / Hypothesis 2: Schema-competition for female students)
// =============================================================================


// =============================================================================
// SECTION 1: SETUP AND DATA PREPARATION
// =============================================================================

// --- 1.1. Basic Setup and Data Loading ---
clear all
// ** IMPORTANT **: Please modify the file path below to the location of your data file.

// (Path for original user)
use "C:/Users/ysh96/OneDrive - Louisiana State University/Working Paper/Social Media & Fertility/Social_Media_Fertility_Weight_2018-2020_Processed.dta"
// (For new users): Set this path to your local data file
// use "YOUR/PATH/TO/Social_Media_Fertility_Weight_2018-2020_Processed.dta"


// --- 1.2. Variable Recoding and Generation ---

// Dependent Variable: Desired Number of Children (0 / 1+ / Don't know)
gen Desired_Children_Recode_new = .
replace Desired_Children_Recode_new = 1 if inlist(Desired_Children, 1) // 0 Children
replace Desired_Children_Recode_new = 2 if inlist(Desired_Children, 2, 3, 4, 5, 6, 7) // 1+ Children
replace Desired_Children_Recode_new = 3 if Desired_Children == 8 // Don't know
label define Desired_Children_lbl_new 1 "0_Child" 2 "1__Child" 3 "Don_t_Know"
label values Desired_Children_Recode_new Desired_Children_lbl_new

// Key Grouping Variable: Gender
gen Gender_Recode = .
replace Gender_Recode = 1 if Gender == 1 // Male
replace Gender_Recode = 2 if Gender == 2 // Female
label define Gender_lbl 1 "Men" 2 "Women"
label values Gender_Recode Gender_lbl

// Variable for selecting analysis period
gen Covid_Period = .
replace Covid_Period = 1 if Survey_Year <= 2020 // Pre-pandemic (2018-2020)
replace Covid_Period = 2 if Survey_Year > 2020  // Post-pandemic (2021-2023)

// =============================================================================
// Key Independent Variables - All standardized to 4 categories
// =============================================================================

// (1) Social Media
gen Social_Media_Hours_Cat = .
replace Social_Media_Hours_Cat = 1 if Social_Media_Hours == 1       // None
replace Social_Media_Hours_Cat = 2 if Social_Media_Hours == 2       // < 1 hour
replace Social_Media_Hours_Cat = 3 if inlist(Social_Media_Hours, 3, 4)  // 1-4 hours
replace Social_Media_Hours_Cat = 4 if inlist(Social_Media_Hours, 5, 6, 7) // 5+ hours
label define Social_Media_Hours_lbl 1 "None" 2 "< 1 hr" 3 "1-4 hrs" 4 "5+ hrs"
label values Social_Media_Hours_Cat Social_Media_Hours_lbl

// (2) Gaming
gen Gaming_Hours_Cat = .
replace Gaming_Hours_Cat = 1 if Gaming_Hours == 1       // None
replace Gaming_Hours_Cat = 2 if Gaming_Hours == 2       // < 1 hour
replace Gaming_Hours_Cat = 3 if inlist(Gaming_Hours, 3, 4)  // 1-4 hours
replace Gaming_Hours_Cat = 4 if inlist(Gaming_Hours, 5, 6, 7) // 5+ hours
label define Gaming_Hours_lbl 1 "None" 2 "< 1 hr" 3 "1-4 hrs" 4 "5+ hrs"
label values Gaming_Hours_Cat Gaming_Hours_lbl

// (3) Weekday Video
gen Weekday_Video_Hours_Cat = .
replace Weekday_Video_Hours_Cat = 1 if Weekday_Video_Hours == 1
replace Weekday_Video_Hours_Cat = 2 if Weekday_Video_Hours == 2
replace Weekday_Video_Hours_Cat = 3 if inlist(Weekday_Video_Hours, 3, 4)
replace Weekday_Video_Hours_Cat = 4 if inlist(Weekday_Video_Hours, 5, 6, 7)
label define Weekday_Video_lbl 1 "None" 2 "< 1 hr" 3 "1-4 hrs" 4 "5+ hrs"
label values Weekday_Video_Hours_Cat Weekday_Video_lbl

// (4) Weekend Video
gen Weekend_Video_Hours_Cat = .
replace Weekend_Video_Hours_Cat = 1 if Weekend_Video_Hours == 1
replace Weekend_Video_Hours_Cat = 2 if Weekend_Video_Hours == 2
replace Weekend_Video_Hours_Cat = 3 if inlist(Weekend_Video_Hours, 3, 4)
replace Weekend_Video_Hours_Cat = 4 if inlist(Weekend_Video_Hours, 5, 6, 7)
label define Weekend_Video_lbl 1 "None" 2 "< 1 hr" 3 "1-4 hrs" 4 "5+ hrs"
label values Weekend_Video_Hours_Cat Weekend_Video_lbl

// =============================================================================
// Control Variables
// =============================================================================

gen Race_Recode = .
replace Race_Recode = 1 if Race == 1
replace Race_Recode = 2 if Race == 2
replace Race_Recode = 3 if Race == 3
replace Race_Recode = 4 if Race > 3 | Race == .
label define Race_lbl 1 "Black" 2 "White" 3 "Hispanic" 4 "NA+Others"
label values Race_Recode Race_lbl

gen City_Size_Recode = .
replace City_Size_Recode = 1 if inlist(City_Size, 2, 3)
replace City_Size_Recode = 2 if inlist(City_Size, 4, 5, 6)
replace City_Size_Recode = 3 if inlist(City_Size, 7, 8, 9, 10)
replace City_Size_Recode = 4 if City_Size == 1 | City_Size == .
label define City_Size_lbl 1 "Rural" 2 "Small/Med City" 3 "Large City" 4 "DK/MIXED+NA"
label values City_Size_Recode City_Size_lbl

gen Combined_Living_Arrangement = .
replace Combined_Living_Arrangement = 1 if Lives_with_Mother == 2 & Lives_with_Father == 2
replace Combined_Living_Arrangement = 2 if Lives_with_Mother != 2 & Lives_with_Father == 2
replace Combined_Living_Arrangement = 3 if Lives_with_Mother == 2 & Lives_with_Father != 2
replace Combined_Living_Arrangement = 4 if (Lives_with_Mother != 2 & Lives_with_Father != 2) | (Lives_with_Mother == . & Lives_with_Father == .)
label define Living_Arrange_lbl 1 "Both Parents" 2 "Father Only" 3 "Mother Only" 4 "Neither/NA"
label values Combined_Living_Arrangement Living_Arrange_lbl

gen Poli_Beli_grp = .
replace Poli_Beli_grp = 1 if inlist(Poli_Beli, 1, 2)
replace Poli_Beli_grp = 2 if Poli_Beli == 3
replace Poli_Beli_grp = 3 if inlist(Poli_Beli, 4, 5, 6)
replace Poli_Beli_grp = 4 if Poli_Beli == 7
label define PoliBeliGrp 1 "Conservative" 2 "Moderate" 3 "Liberal" 4 "None/Don't know"
label values Poli_Beli_grp PoliBeliGrp


// --- 1.3. Construct Final Analytical Dataset ---
// Keep only pre-pandemic data (2018-2020) for analysis
keep if Covid_Period == 1
// Keep only male and female respondents
keep if Gender_Recode == 1 | Gender_Recode == 2

// =============================================================================
// SECTION 2: MAIN ANALYSIS (Revised: All media variables as categorical)
// =============================================================================

// --- Define Global Macros ---
// (Note: Updated to include specific controls for all 4 models)
global controls "i.Religion_Importance c.Siblings i.Happiness_Level c.Date_Wk i.City_Size_Recode i.Race_Recode i.Combined_Living_Arrangement i.Mother_Education i.Father_Education i.Poli_Beli_grp i.Survey_Year"

// Controls for Social Media model
global media_controls_sm "i.Gaming_Hours_Cat i.Weekday_Video_Hours_Cat i.Weekend_Video_Hours_Cat"
// Controls for Gaming model
global media_controls_ga "i.Social_Media_Hours_Cat i.Weekday_Video_Hours_Cat i.Weekend_Video_Hours_Cat"
// Controls for Weekday Video model (NEW)
global media_controls_wv "i.Social_Media_Hours_Cat i.Gaming_Hours_Cat i.Weekend_Video_Hours_Cat"
// Controls for Weekend Video model (NEW)
global media_controls_wev "i.Social_Media_Hours_Cat i.Gaming_Hours_Cat i.Weekday_Video_Hours_Cat"


// --- 2.1. Testing Gender Differences in Social Media Effects ---
mlogit Desired_Children_Recode_new i.Social_Media_Hours_Cat##i.Gender_Recode ///
    $media_controls_sm $controls [pweight=ARCHIVE_WT], baseoutcome(1)
est store m_social_media

// Calculate Average Marginal Effects (AME) by gender (all outcomes)
di " "
di "=== SOCIAL MEDIA: Average Marginal Effects by Gender ==="

di "--- Outcome: 0 Child ---"
margins, dydx(Social_Media_Hours_Cat) at(Gender_Recode=(1 2)) predict(outcome(1))

di "--- Outcome: 1+ Child ---"
margins, dydx(Social_Media_Hours_Cat) at(Gender_Recode=(1 2)) predict(outcome(2))

di "--- Outcome: Don't Know ---"
margins, dydx(Social_Media_Hours_Cat) at(Gender_Recode=(1 2)) predict(outcome(3))

// Test for differences in effects between genders
di " "
di "=== SOCIAL MEDIA: Gender Difference Tests ==="

di "--- Gender Difference (Outcome: 0 Child) ---"
margins r.Gender_Recode, dydx(Social_Media_Hours_Cat) predict(outcome(1))

di "--- Gender Difference (Outcome: 1+ Child) ---"
margins r.Gender_Recode, dydx(Social_Media_Hours_Cat) predict(outcome(2))

di "--- Gender Difference (Outcome: Don't Know) ---"
margins r.Gender_Recode, dydx(Social_Media_Hours_Cat) predict(outcome(3))

// Visualize predicted probabilities (1+ Child)
margins Gender_Recode, at(Social_Media_Hours_Cat=(1(1)4)) predict(outcome(2)) post
marginsplot, ///
    xdimension(Social_Media_Hours_Cat) noci ///
    plot1opts(lcolor(blue) lpattern(solid) mcolor(blue)) ///
    plot2opts(lcolor(red) lpattern(dash) mcolor(red)) ///
    xtitle("Social Media Usage") ytitle("Predicted Probability of Desiring 1+ Children") ///
    title("Social Media Effect by Gender (Pre-COVID)", size(medium)) ///
    legend(order(1 "Men" 2 "Women")) graphregion(color(white))
// (For new users): Uncomment and set path to save the graph
// graph export "YOUR/GRAPH/OUTPUT/PATH/GenderDiff_SocialMedia_PreCovid.png", replace


// --- 2.2. Testing Gender Differences in Gaming Effects ---
mlogit Desired_Children_Recode_new i.Gaming_Hours_Cat##i.Gender_Recode ///
    $media_controls_ga $controls [pweight=ARCHIVE_WT], baseoutcome(1)
est store m_gaming

// Calculate Average Marginal Effects (AME) by gender (all outcomes)
di " "
di "=== GAMING: Average Marginal Effects by Gender ==="

di "--- Outcome: 0 Child ---"
margins, dydx(Gaming_Hours_Cat) at(Gender_Recode=(1 2)) predict(outcome(1))

di "--- Outcome: 1+ Child ---"
margins, dydx(Gaming_Hours_Cat) at(Gender_Recode=(1 2)) predict(outcome(2))

di "--- Outcome: Don't Know ---"
margins, dydx(Gaming_Hours_Cat) at(Gender_Recode=(1 2)) predict(outcome(3))

// Test for differences in effects between genders
di " "
di "=== GAMING: Gender Difference Tests ==="

di "--- Gender Difference (Outcome: 0 Child) ---"
margins r.Gender_Recode, dydx(Gaming_Hours_Cat) predict(outcome(1))

di "--- Gender Difference (Outcome: 1+ Child) ---"
margins r.Gender_Recode, dydx(Gaming_Hours_Cat) predict(outcome(2))

di "--- Gender Difference (Outcome: Don't Know) ---"
margins r.Gender_Recode, dydx(Gaming_Hours_Cat) predict(outcome(3))

// Visualize predicted probabilities (1+ Child)
margins Gender_Recode, at(Gaming_Hours_Cat=(1(1)4)) predict(outcome(2)) post
marginsplot, ///
    xdimension(Gaming_Hours_Cat) noci ///
    plot1opts(lcolor(blue) lpattern(solid) mcolor(blue)) ///
    plot2opts(lcolor(red) lpattern(dash) mcolor(red)) ///
    xtitle("Gaming Hours") ytitle("Predicted Probability of Desiring 1+ Children") ///
    title("Gaming Effect by Gender (Pre-COVID)", size(medium)) ///
    legend(order(1 "Men" 2 "Women")) graphregion(color(white))
// (For new users): Uncomment and set path to save the graph
// graph export "YOUR/GRAPH/OUTPUT/PATH/GenderDiff_Gaming_PreCovid.png", replace


// =============================================================================
// --- 2.3. Testing Gender Differences in Weekday Video Effects (NEW) ---
// =============================================================================
mlogit Desired_Children_Recode_new i.Weekday_Video_Hours_Cat##i.Gender_Recode ///
    $media_controls_wv $controls [pweight=ARCHIVE_WT], baseoutcome(1)
est store m_weekday_video

// Calculate Average Marginal Effects (AME) by gender (all outcomes)
di " "
di "=== WEEKDAY VIDEO: Average Marginal Effects by Gender ==="

di "--- Outcome: 0 Child ---"
margins, dydx(Weekday_Video_Hours_Cat) at(Gender_Recode=(1 2)) predict(outcome(1))

di "--- Outcome: 1+ Child ---"
margins, dydx(Weekday_Video_Hours_Cat) at(Gender_Recode=(1 2)) predict(outcome(2))

di "--- Outcome: Don't Know ---"
margins, dydx(Weekday_Video_Hours_Cat) at(Gender_Recode=(1 2)) predict(outcome(3))

// Test for differences in effects between genders
di " "
di "=== WEEKDAY VIDEO: Gender Difference Tests ==="

di "--- Gender Difference (Outcome: 0 Child) ---"
margins r.Gender_Recode, dydx(Weekday_Video_Hours_Cat) predict(outcome(1))

di "--- Gender Difference (Outcome: 1+ Child) ---"
margins r.Gender_Recode, dydx(Weekday_Video_Hours_Cat) predict(outcome(2))

di "--- Gender Difference (Outcome: Don't Know) ---"
margins r.Gender_Recode, dydx(Weekday_Video_Hours_Cat) predict(outcome(3))

// Visualize predicted probabilities (1+ Child)
margins Gender_Recode, at(Weekday_Video_Hours_Cat=(1(1)4)) predict(outcome(2)) post
marginsplot, ///
    xdimension(Weekday_Video_Hours_Cat) noci ///
    plot1opts(lcolor(blue) lpattern(solid) mcolor(blue)) ///
    plot2opts(lcolor(red) lpattern(dash) mcolor(red)) ///
    xtitle("Weekday Video Hours") ytitle("Predicted Probability of Desiring 1+ Children") ///
    title("Weekday Video Effect by Gender (Pre-COVID)", size(medium)) ///
    legend(order(1 "Men" 2 "Women")) graphregion(color(white))
// (For new users): Uncomment and set path to save the graph
// graph export "YOUR/GRAPH/OUTPUT/PATH/GenderDiff_WeekdayVideo_PreCovid.png", replace


// =============================================================================
// --- 2.4. Testing Gender Differences in Weekend Video Effects (NEW) ---
// =============================================================================
mlogit Desired_Children_Recode_new i.Weekend_Video_Hours_Cat##i.Gender_Recode ///
    $media_controls_wev $controls [pweight=ARCHIVE_WT], baseoutcome(1)
est store m_weekend_video

// Calculate Average Marginal Effects (AME) by gender (all outcomes)
di " "
di "=== WEEKEND VIDEO: Average Marginal Effects by Gender ==="

di "--- Outcome: 0 Child ---"
margins, dydx(Weekend_Video_Hours_Cat) at(Gender_Recode=(1 2)) predict(outcome(1))

di "--- Outcome: 1+ Child ---"
margins, dydx(Weekend_Video_Hours_Cat) at(Gender_Recode=(1 2)) predict(outcome(2))

di "--- Outcome: Don't Know ---"
margins, dydx(Weekend_Video_Hours_Cat) at(Gender_Recode=(1 2)) predict(outcome(3))

// Test for differences in effects between genders
di " "
di "=== WEEKEND VIDEO: Gender Difference Tests ==="

di "--- Gender Difference (Outcome: 0 Child) ---"
margins r.Gender_Recode, dydx(Weekend_Video_Hours_Cat) predict(outcome(1))

di "--- Gender Difference (Outcome: 1+ Child) ---"
margins r.Gender_Recode, dydx(Weekend_Video_Hours_Cat) predict(outcome(2))

di "--- Gender Difference (Outcome: Don't Know) ---"
margins r.Gender_Recode, dydx(Weekend_Video_Hours_Cat) predict(outcome(3))

// Visualize predicted probabilities (1+ Child)
margins Gender_Recode, at(Weekend_Video_Hours_Cat=(1(1)4)) predict(outcome(2)) post
marginsplot, ///
    xdimension(Weekend_Video_Hours_Cat) noci ///
    plot1opts(lcolor(blue) lpattern(solid) mcolor(blue)) ///
    plot2opts(lcolor(red) lpattern(dash) mcolor(red)) ///
    xtitle("Weekend Video Hours") ytitle("Predicted Probability of Desiring 1+ Children") ///
    title("Weekend Video Effect by Gender (Pre-COVID)", size(medium)) ///
    legend(order(1 "Men" 2 "Women")) graphregion(color(white))
// (For new users): Uncomment and set path to save the graph
// graph export "YOUR/GRAPH/OUTPUT/PATH/GenderDiff_WeekendVideo_PreCovid.png", replace

// =============================================================================
// SECTION 3: APPENDIX - DESCRIPTIVE STATISTICS
// =============================================================================

// svyset setup
svyset [pweight=ARCHIVE_WT], clear

di " "
di "*** SECTION 3: GENERATING APPENDIX TABLE A1 (DESCRIPTIVE STATISTICS) ***"

// --- 3.1. Total Sample (N=4,740) ---
di " "
di "--- DESCRIPTIVES: TOTAL SAMPLE (N=4,740) ---"
di "--- Continuous Variables (Mean) - Total ---"
svy: mean Siblings Date_Wk

di "--- Categorical Variables (Percent) - Total ---"
svy: tab Desired_Children_Recode_new, percent
svy: tab Social_Media_Hours_Cat, percent
svy: tab Gaming_Hours_Cat, percent
svy: tab Weekday_Video_Hours_Cat, percent
svy: tab Weekend_Video_Hours_Cat, percent
svy: tab Religion_Importance, percent
svy: tab Happiness_Level, percent
svy: tab City_Size_Recode, percent
svy: tab Race_Recode, percent
svy: tab Combined_Living_Arrangement, percent
svy: tab Mother_Education, percent
svy: tab Father_Education, percent
svy: tab Poli_Beli_grp, percent
svy: tab Survey_Year, percent


// --- 3.2. By Gender: Men ---
di " "
di "--- DESCRIPTIVES: MEN (Gender_Recode == 1) ---"
di "--- Continuous Variables (Mean) - Men ---"
svy, subpop(if Gender_Recode == 1): mean Siblings Date_Wk

di "--- Categorical Variables (Percent) - Men ---"
svy, subpop(if Gender_Recode == 1): tab Desired_Children_Recode_new, percent
svy, subpop(if Gender_Recode == 1): tab Social_Media_Hours_Cat, percent
svy, subpop(if Gender_Recode == 1): tab Gaming_Hours_Cat, percent
svy, subpop(if Gender_Recode == 1): tab Weekday_Video_Hours_Cat, percent
svy, subpop(if Gender_Recode == 1): tab Weekend_Video_Hours_Cat, percent
svy, subpop(if Gender_Recode == 1): tab Religion_Importance, percent
svy, subpop(if Gender_Recode == 1): tab Happiness_Level, percent
svy, subpop(if Gender_Recode == 1): tab City_Size_Recode, percent
svy, subpop(if Gender_Recode == 1): tab Race_Recode, percent
svy, subpop(if Gender_Recode == 1): tab Combined_Living_Arrangement, percent
svy, subpop(if Gender_Recode == 1): tab Mother_Education, percent
svy, subpop(if Gender_Recode == 1): tab Father_Education, percent
svy, subpop(if Gender_Recode == 1): tab Poli_Beli_grp, percent
svy, subpop(if Gender_Recode == 1): tab Survey_Year, percent


// --- 3.3. By Gender: Women ---
di " "
di "--- DESCRIPTIVES: WOMEN (Gender_Recode == 2) ---"
di "--- Continuous Variables (Mean) - Women ---"
svy, subpop(if Gender_Recode == 2): mean Siblings Date_Wk

di "--- Categorical Variables (Percent) - Women ---"
svy, subpop(if Gender_Recode == 2): tab Desired_Children_Recode_new, percent
svy, subpop(if Gender_Recode == 2): tab Social_Media_Hours_Cat, percent
svy, subpop(if Gender_Recode == 2): tab Gaming_Hours_Cat, percent
svy, subpop(if Gender_Recode == 2): tab Weekday_Video_Hours_Cat, percent
svy, subpop(if Gender_Recode == 2): tab Weekend_Video_Hours_Cat, percent
svy, subpop(if Gender_Recode == 2): tab Religion_Importance, percent
svy, subpop(if Gender_Recode == 2): tab Happiness_Level, percent
svy, subpop(if Gender_Recode == 2): tab City_Size_Recode, percent
svy, subpop(if Gender_Recode == 2): tab Race_Recode, percent
svy, subpop(if Gender_Recode == 2): tab Combined_Living_Arrangement, percent
svy, subpop(if Gender_Recode == 2): tab Mother_Education, percent
svy, subpop(if Gender_Recode == 2): tab Father_Education, percent
svy, subpop(if Gender_Recode == 2): tab Poli_Beli_grp, percent
svy, subpop(if Gender_Recode == 2): tab Survey_Year, percent


// --- END OF DO-FILE ---